#ifndef _UIMYPROGRESS_H_
#define _UIMYPROGRESS_H_
#include <mzfc_inc.h>

class UiMyProgress : public UiWin
{
private:
	CMzString m_title;
	UINT m_curVal;
	UINT m_maxVal;
	UINT m_counter;
public:
	UiMyProgress(){ m_curVal = 0; m_maxVal = 1; m_counter = 0; this->SetVisible(false); }
	void SetTitle(CMzString title){ this->m_title = title; }
	void SetCurrentVal(UINT val){ this->m_curVal = val; }
	UINT GetCurrentVal() const { return this->m_curVal; }
	void SetMaxVal(UINT val) { this->m_maxVal = val; }
	UINT GetMaxVal() const { return this->m_maxVal; }
	virtual void  PaintWin(HDC hdcDst, RECT *prcWin, RECT *prcUpdate)
	{
		HFONT f = MzCreateFont(8 * RECT_HEIGHT(*prcWin) / 10);
		HGDIOBJ old = SelectObject(hdcDst,f);
		::SetTextColor(hdcDst, RGB(0,0,0));
		DrawRoundRect(hdcDst,prcWin,2,0xFFFFFF,0xFFFFFF);
		RECT rect = *prcWin;
		rect.right = prcWin->right * this->GetCurrentVal() / this->GetMaxVal();
		DrawRoundRect(hdcDst,&rect,2,0x00FF00,0x00FF00);
		CMzString txt = this->m_title;
		if((this->m_counter % 20) > 9)
		{
			txt = this->m_title.SubStr(0,this->m_title.Length() - 3) + L"  ";
		}
		MzDrawText(hdcDst, txt.C_Str(), prcWin, DT_CENTER|DT_VCENTER|DT_SINGLELINE|DT_END_ELLIPSIS);
		SelectObject(hdcDst,old);
		DeleteObject(f);
	}
	void UpdateProgress()
	{
		++m_counter;
		this->Invalidate();
		this->Update();
	}
	void StartProgress() 
	{
		m_counter = 0;
		this->SetVisible(true);	
		this->UpdateProgress();
	}
	void EndProgress()
	{
		m_counter = 0;
		this->SetVisible(false);
		this->UpdateProgress();
	}
};
#endif
